home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / macros / latex209 / contrib / astron / astron.bst < prev    next >
Text File  |  1990-07-25  |  25KB  |  1,176 lines

  1. % Copyright (C) 1990 Sake J. Hogeveen.
  2.  
  3. % This is ASTRON.BST, a BibTeX style for use with BibTeX version 0.99c.
  4. % ASTRON.BST has to be used in conjunction with the LaTeX style ASTRON.STY.
  5. % The use of both styles is documented in ASTDOC.TEX.
  6.  
  7. % ASTRON.BST is an adaptation of APALIKE.BST by Oren Patashnik and Suzan King.
  8.  
  9. % This style produces citations in the `author-year' format, which is widely
  10. % used among astronomical journals.
  11. % It supports two forms of citation: the \cite command produces:  (Author, year)
  12. % in the text; the \cite* command only:  (year) .
  13.  
  14. % The long an short citation trickery is adapted from NAMED.BST by
  15. % Peter F. Patel-Schneider.
  16.  
  17. % Copyright Notice:
  18. % The files ASTRON.BST, ASTRON.STY, ASTDOC.TEX, ASTDOC.BIB, EXAMPLE.TEX,
  19. % EXAMPLE.BIB, MNEMONIC.BIB, and TEMPLATE.BIB are a package.
  20. % You may copy and distribute them freely for non-commercial purposes,
  21. % provided that you keep the package together and this copyright notice
  22. % in tact.
  23. % You may not alter or modify the files; this helps to ensure that all
  24. % distributions of ASTRON.BST and related files are the same.
  25. % If you make any modifications, then you must give the files new names,
  26. % other than the present.
  27. % The author bears no responsibilities for errors in this document or
  28. % the software it describes; and shall not be held liable for any indirect,
  29. % incidental, or consequential damages.
  30.  
  31. ENTRY
  32.   { address
  33.     author
  34.     booktitle
  35.     chapter
  36.     edition
  37.     editor
  38.     howpublished
  39.     institution
  40.     journal
  41.     key
  42. %    month              not used in apalike
  43.     note
  44.     number
  45.     organization
  46.     pages
  47.     publisher
  48.     school
  49.     series
  50.     title
  51.     type
  52.     volume
  53.     year
  54.   }
  55.   {}
  56.   { label extra.label sort.label }
  57.  
  58. INTEGERS { output.state before.all mid.sentence after.sentence after.block }
  59.  
  60. FUNCTION {init.state.consts}
  61. { #0 'before.all :=
  62.   #1 'mid.sentence :=
  63.   #2 'after.sentence :=
  64.   #3 'after.block :=
  65. }
  66.  
  67. STRINGS { s t }
  68.  
  69. FUNCTION {output.nonnull}
  70. { 's :=
  71.   output.state mid.sentence =
  72.     { ", " * write$ }
  73.     { output.state after.block =
  74.         { ", " *  write$
  75.           newline$
  76.           "\newblock " write$
  77.         }
  78.         { output.state before.all =
  79.             'write$
  80.             { ", " * write$ }
  81.           if$
  82.         }
  83.       if$
  84.       mid.sentence 'output.state :=
  85.     }
  86.   if$
  87.   s
  88. }
  89.  
  90. FUNCTION {output.nonnull.extra}
  91. { 's :=
  92.   output.state mid.sentence =
  93.     { " " * write$ }
  94.     { output.state after.block =
  95.         { ", " *  write$
  96.           newline$
  97.           "\newblock " write$
  98.         }
  99.         { output.state before.all =
  100.             'write$
  101.             { ", " * write$ }
  102.           if$
  103.         }
  104.       if$
  105.       mid.sentence 'output.state :=
  106.     }
  107.   if$
  108.   s
  109. }
  110.  
  111. FUNCTION {output}
  112. { duplicate$ empty$
  113.     'pop$
  114.     'output.nonnull
  115.   if$
  116. }
  117.  
  118. FUNCTION {output.extra}
  119. { duplicate$ empty$
  120.     'pop$
  121.     'output.nonnull.extra
  122.   if$
  123. }
  124.  
  125. FUNCTION {output.check}
  126. { 't :=
  127.   duplicate$ empty$
  128.     { pop$ "empty " t * " in " * cite$ * warning$ }
  129.     'output.nonnull
  130.   if$
  131. }
  132.  
  133. FUNCTION {output.check.extra}
  134. { 't :=
  135.   duplicate$ empty$
  136.     { pop$ "empty " t * " in " * cite$ * warning$ }
  137.     'output.nonnull.extra
  138.   if$
  139. }
  140.  
  141. %                                       apalike needs this function because
  142. %                                       the year has special punctuation;
  143. %                                       apalike ignores the month
  144. FUNCTION {output.year.check}
  145. { year empty$
  146.     { "empty year in " cite$ * warning$ }
  147.     { write$
  148.       ": " year * extra.label *
  149.       mid.sentence 'output.state :=
  150.     }
  151.   if$
  152. }
  153.  
  154. FUNCTION {output.bibitem}
  155. { newline$
  156.   "\bibitem[" write$
  157.   label write$
  158.   "]{" write$
  159.   cite$ write$
  160.   "}" write$
  161.   newline$
  162.   ""
  163.   before.all 'output.state :=
  164. }
  165.  
  166. FUNCTION {fin.entry}
  167. { write$
  168.   newline$
  169. }
  170.  
  171. FUNCTION {new.block}
  172. { output.state before.all =
  173.     'skip$
  174.     { after.block 'output.state := }
  175.   if$
  176. }
  177.  
  178. FUNCTION {new.sentence}
  179. { output.state after.block =
  180.     'skip$
  181.     { output.state before.all =
  182.         'skip$
  183.         { after.sentence 'output.state := }
  184.       if$
  185.     }
  186.   if$
  187. }
  188.  
  189. FUNCTION {not}
  190. {   { #0 }
  191.     { #1 }
  192.   if$
  193. }
  194.  
  195. FUNCTION {and}
  196. {   'skip$
  197.     { pop$ #0 }
  198.   if$
  199. }
  200.  
  201. FUNCTION {or}
  202. {   { pop$ #1 }
  203.     'skip$
  204.   if$
  205. }
  206.  
  207. FUNCTION {new.block.checkb}
  208. { empty$
  209.   swap$ empty$
  210.   and
  211.     'skip$
  212.     'new.block
  213.   if$
  214. }
  215.  
  216. FUNCTION {field.or.null}
  217. { duplicate$ empty$
  218.     { pop$ "" }
  219.     'skip$
  220.   if$
  221. }
  222.  
  223. FUNCTION {boldface}
  224. { duplicate$ empty$
  225.     { pop$ "" }
  226.     { "{\bf " swap$ * "}" * }
  227.   if$
  228. }
  229.  
  230. FUNCTION {emphasize}
  231. { duplicate$ empty$
  232.     { pop$ "" }
  233.     { "{\em " swap$ * "}" * }
  234.   if$
  235. }
  236.  
  237. INTEGERS { nameptr namesleft numnames }
  238.  
  239. FUNCTION {format.names}
  240. { 's :=
  241.   #1 'nameptr :=
  242.   s num.names$ 'numnames :=
  243.   numnames 'namesleft :=
  244.     { namesleft #0 > }
  245.     { s nameptr "{vv~}{ll}{, jj}{, f.}" format.name$ 't :=   % last name first
  246.       nameptr #1 >
  247.         { namesleft #1 >
  248.             { ", " * t * }
  249.             { numnames #2 >
  250.                 { "," * }
  251.                 'skip$
  252.               if$
  253.               t "others" =
  254.                 { " et~al." * }
  255.                 { " and " * t * }
  256.               if$
  257.             }
  258.           if$
  259.         }
  260.         't
  261.       if$
  262.       nameptr #1 + 'nameptr :=
  263.       namesleft #1 - 'namesleft :=
  264.     }
  265.   while$
  266. }
  267.  
  268. FUNCTION {format.ed.names}
  269. { 's :=
  270.   #1 'nameptr :=
  271.   s num.names$ 'numnames :=
  272.   numnames 'namesleft :=
  273.     { namesleft #0 > }
  274.     { s nameptr "{f. }{vv~}{ll}{, jj}" format.name$ 't :=
  275.       nameptr #1 >
  276.         { namesleft #1 >
  277.             { ", " * t * }
  278.             { numnames #2 >
  279.                 { "," * }
  280.                 'skip$
  281.               if$
  282.               t "others" =
  283.                 { " et~al." * }
  284.                 { " and " * t * }
  285.               if$
  286.             }
  287.           if$
  288.         }
  289.         't
  290.       if$
  291.       nameptr #1 + 'nameptr :=
  292.       namesleft #1 - 'namesleft :=
  293.     }
  294.   while$
  295. }
  296.  
  297. FUNCTION {format.authors}
  298. { author empty$
  299.     { "" }
  300.     { author format.names }
  301.   if$
  302. }
  303.  
  304. FUNCTION {format.key}                   % this function is just for apalike
  305. { empty$
  306.     { key field.or.null }
  307.     { "" }
  308.   if$
  309. }
  310.  
  311. FUNCTION {format.editors}
  312. { editor empty$
  313.     { "" }
  314.     { editor format.names
  315.       editor num.names$ #1 >
  316.         { " (eds.)" * }
  317.         { " (ed.)" * }
  318.       if$
  319.     }
  320.   if$
  321. }
  322.  
  323. FUNCTION {format.editors.extra}
  324. { editor empty$
  325.     { "" }
  326.     { editor format.ed.names
  327.       editor num.names$ #1 >
  328.         { " (eds.)" * }
  329.         { " (ed.)" * }
  330.       if$
  331.     }
  332.   if$
  333. }
  334.  
  335. FUNCTION {format.title}
  336. { title empty$
  337.     { "" }
  338.     { title "t" change.case$ }
  339.   if$
  340. }
  341.  
  342. FUNCTION {n.dashify}
  343. { 't :=
  344.   ""
  345.     { t empty$ not }
  346.     { t #1 #1 substring$ "-" =
  347.         { t #1 #2 substring$ "--" = not
  348.             { "--" *
  349.               t #2 global.max$ substring$ 't :=
  350.             }
  351.             {   { t #1 #1 substring$ "-" = }
  352.                 { "-" *
  353.                   t #2 global.max$ substring$ 't :=
  354.                 }
  355.               while$
  356.             }
  357.           if$
  358.         }
  359.         { t #1 #1 substring$ *
  360.           t #2 global.max$ substring$ 't :=
  361.         }
  362.       if$
  363.     }
  364.   while$
  365. }
  366.  
  367. FUNCTION {first.page.number}
  368. { 't :=
  369.   ""
  370.     { t "" =
  371.         { #0 }
  372.         { t #1 #1 substring$ "-" = not }
  373.       if$
  374.     }
  375.     { t #1 #1 substring$ *
  376.       t #2 global.max$ substring$ 't :=
  377.     }
  378.   while$
  379. }
  380.  
  381. FUNCTION {format.btitle}
  382. { title emphasize
  383. }
  384.  
  385. FUNCTION {tie.or.space.connect}
  386. { duplicate$ text.length$ #3 <
  387.     { "~" }
  388.     { " " }
  389.   if$
  390.   swap$ * *
  391. }
  392.  
  393. FUNCTION {either.or.check}
  394. { empty$
  395.     'pop$
  396.     { "can't use both " swap$ * " fields in " * cite$ * warning$ }
  397.   if$
  398. }
  399.  
  400. FUNCTION {format.bvolume}
  401. { volume empty$
  402.     { "" }
  403.     { "Vol." volume tie.or.space.connect
  404.       series empty$
  405.         'skip$
  406.         { " of " * series emphasize * }
  407.       if$
  408.       "volume and number" number either.or.check
  409.     }
  410.   if$
  411. }
  412.  
  413. FUNCTION {format.number.series}
  414. { volume empty$
  415.     { number empty$
  416.         { series field.or.null }
  417.         { output.state mid.sentence =
  418.             { "No." }
  419.             { "No." }
  420.           if$
  421.           number tie.or.space.connect
  422.           series empty$
  423.             { "there's a number but no series in " cite$ * warning$ }
  424.             { " in " * series * }
  425.           if$
  426.         }
  427.       if$
  428.     }
  429.     { "" }
  430.   if$
  431. }
  432.  
  433. FUNCTION {format.edition}
  434. { edition empty$
  435.     { "" }
  436.     { output.state mid.sentence =
  437.         { edition "l" change.case$ " edition" * }
  438.         { edition "t" change.case$ " edition" * }
  439.       if$
  440.     }
  441.   if$
  442. }
  443.  
  444. INTEGERS { multiresult }
  445.  
  446. FUNCTION {multi.page.check}
  447. { 't :=
  448.   #0 'multiresult :=
  449.     { multiresult not
  450.       t empty$ not
  451.       and
  452.     }
  453.     { t #1 #1 substring$
  454.       duplicate$ "-" =
  455.       swap$ duplicate$ "," =
  456.       swap$ "+" =
  457.       or or
  458.         { #1 'multiresult := }
  459.         { t #2 global.max$ substring$ 't := }
  460.       if$
  461.     }
  462.   while$
  463.   multiresult
  464. }
  465.  
  466. FUNCTION {format.pages}
  467. { pages empty$
  468.     { "" }
  469.     { pages multi.page.check
  470.     { "pp" pages n.dashify tie.or.space.connect }
  471.     { "p." pages tie.or.space.connect }
  472.       if$
  473.     }
  474.   if$
  475. }
  476.  
  477. FUNCTION {format.page}
  478. { pages empty$
  479.     { "" }
  480.     { "p.~" pages first.page.number * }
  481.   if$
  482. }
  483.  
  484. FUNCTION {format.vol.num.pages}
  485. { volume field.or.null
  486.   number empty$
  487.     'skip$
  488.     { "(" number * ")" * *
  489.       volume empty$
  490.         { "there's a number but no volume in " cite$ * warning$ }
  491.         'skip$
  492.       if$
  493.     }
  494.   if$
  495.   pages empty$
  496.     'skip$
  497.     { duplicate$ empty$
  498.         { pop$ format.pages }
  499.         { boldface ", " * pages n.dashify * }
  500.       if$
  501.     }
  502.   if$
  503. }
  504.  
  505. FUNCTION {format.vol.num.page}
  506. { volume field.or.null
  507.   number empty$
  508.     'skip$
  509.     { "(" number * ")" * *
  510.       volume empty$
  511.         { "there's a number but no volume in " cite$ * warning$ }
  512.         'skip$
  513.       if$
  514.     }
  515.   if$
  516.   pages empty$
  517.     'skip$
  518.     { duplicate$ empty$
  519.         { pop$ format.pages }
  520.         { boldface ", " * pages first.page.number * }
  521.       if$
  522.     }
  523.   if$
  524. }
  525.  
  526. FUNCTION {format.chapter.pages}
  527. { chapter empty$
  528.     'format.pages
  529.     { type empty$
  530.         { "Chapt." }
  531.         { type "l" change.case$ }
  532.       if$
  533.       chapter tie.or.space.connect
  534.       pages empty$
  535.         'skip$
  536.         { ", " * format.pages * }
  537.       if$
  538.     }
  539.   if$
  540. }
  541.  
  542. FUNCTION {format.in.ed.booktitle}
  543. { booktitle empty$
  544.     { "" }
  545.     { editor empty$
  546.         { "in " booktitle emphasize * }
  547.     { "in " format.editors.extra * ", " * booktitle emphasize * }
  548.       if$
  549.     }
  550.   if$
  551. }
  552.  
  553. FUNCTION {format.thesis.type}
  554. { type empty$
  555.     'skip$
  556.     { pop$
  557.       type "t" change.case$
  558.     }
  559.   if$
  560. }
  561.  
  562. FUNCTION {format.tr.number}
  563. { type empty$
  564.     { "Technical Report" }
  565.     'type
  566.   if$
  567.   number empty$
  568.     { "t" change.case$ }
  569.     { number tie.or.space.connect }
  570.   if$
  571. }
  572.  
  573. FUNCTION {format.article.crossref}
  574. { "in"                                                  % this is for apalike
  575.   " \cite{" * crossref * "}" *
  576. }
  577.  
  578. FUNCTION {format.book.crossref}
  579. { volume empty$
  580.     { "empty volume in " cite$ * "'s crossref of " * crossref * warning$
  581.       "in "
  582.     }
  583.     { "Vol." volume tie.or.space.connect
  584.       " of " *
  585.     }
  586.   if$
  587.   "\cite{" * crossref * "}" *                           % this is for apalike
  588. }
  589.  
  590. FUNCTION {format.incoll.inproc.crossref}
  591. { "in"                                                  % this is for apalike
  592.   " \cite{" * crossref * "}" *
  593. }
  594.  
  595. FUNCTION {article}
  596. { output.bibitem
  597.   format.authors "author" output.check
  598.   author format.key output                              % special for
  599.   output.year.check                                     % apalike
  600.   new.block
  601.   crossref missing$
  602.     { journal emphasize "journal" output.check.extra
  603.       format.vol.num.page output.extra
  604.     }
  605.     { format.article.crossref output.nonnull
  606.       format.page output
  607.     }
  608.   if$
  609.   new.block
  610.   note output
  611.   fin.entry
  612. }
  613.  
  614. FUNCTION {book}
  615. { output.bibitem
  616.   author empty$
  617.     { format.editors "author and editor" output.check
  618.       editor format.key output
  619.     }
  620.     { format.authors output.nonnull
  621.       crossref missing$
  622.         { "author and editor" editor either.or.check }
  623.         'skip$
  624.       if$
  625.     }
  626.   if$
  627.   output.year.check                             % special for apalike
  628.   new.block
  629.   format.btitle "title" output.check
  630.   crossref missing$
  631.     { format.bvolume output
  632.       new.block
  633.       format.number.series output
  634.       new.sentence
  635.       publisher "publisher" output.check
  636.       address output
  637.     }
  638.     { new.block
  639.       format.book.crossref output.nonnull
  640.     }
  641.   if$
  642.   format.edition output
  643.   new.block
  644.   note output
  645.   fin.entry
  646. }
  647.  
  648. FUNCTION {booklet}
  649. { output.bibitem
  650.   format.authors output
  651.   author format.key output                              % special for
  652.   output.year.check                                     % apalike
  653.   new.block
  654.   format.btitle "title" output.check
  655.   new.block
  656.   howpublished output
  657.   address output
  658.   new.block
  659.   note output
  660.   fin.entry
  661. }
  662.  
  663. FUNCTION {inbook}
  664. { output.bibitem
  665.   author empty$
  666.     { format.editors "author and editor" output.check
  667.       editor format.key output
  668.     }
  669.     { format.authors output.nonnull
  670.       crossref missing$
  671.         { "author and editor" editor either.or.check }
  672.         'skip$
  673.       if$
  674.     }
  675.   if$
  676.   output.year.check                             % special for apalike
  677.   new.block
  678.   format.btitle "title" output.check
  679.   crossref missing$
  680.     { format.bvolume output
  681.       format.chapter.pages "chapter and pages" output.check
  682.       new.block
  683.       format.number.series output
  684.       new.sentence
  685.       publisher "publisher" output.check
  686.       address output
  687.     }
  688.     { format.chapter.pages "chapter and pages" output.check
  689.       new.block
  690.       format.book.crossref output.nonnull
  691.     }
  692.   if$
  693.   format.edition output
  694.   new.block
  695.   note output
  696.   fin.entry
  697. }
  698.  
  699. FUNCTION {incollection}
  700. { output.bibitem
  701.   format.authors "author" output.check
  702.   author format.key output                              % special for
  703.   output.year.check                                     % apalike
  704.   new.block
  705. %  format.title "title" output.check
  706. %  new.block
  707.   crossref missing$
  708.     { format.in.ed.booktitle "booktitle" output.check
  709.       format.bvolume output
  710.       format.number.series output
  711.       format.chapter.pages output
  712.       new.sentence
  713.       publisher "publisher" output.check
  714.       address output
  715.       format.edition output
  716.     }
  717.     { format.incoll.inproc.crossref output.nonnull
  718.       format.chapter.pages output
  719.     }
  720.   if$
  721.   new.block
  722.   note output
  723.   fin.entry
  724. }
  725.  
  726. FUNCTION {inproceedings}
  727. { output.bibitem
  728.   format.authors "author" output.check
  729.   author format.key output                              % special for
  730.   output.year.check                                     % apalike
  731.   new.block
  732. %  format.title "title" output.check
  733. %  new.block
  734.   crossref missing$
  735.     { format.in.ed.booktitle "booktitle" output.check
  736.       format.bvolume output
  737.       format.number.series output
  738.       format.pages output
  739.       new.sentence                                      % there's no year
  740.       organization output                               % here so things
  741.       publisher output                                  % are simpler
  742.       address output                                    % for apalike
  743.     }
  744.     { format.incoll.inproc.crossref output.nonnull
  745.       format.pages output
  746.     }
  747.   if$
  748.   new.block
  749.   note output
  750.   fin.entry
  751. }
  752.  
  753. FUNCTION {conference} { inproceedings }
  754.  
  755. FUNCTION {manual}
  756. { output.bibitem
  757.   format.authors output
  758.   author format.key output                              % special for
  759.   output.year.check                                     % apalike
  760.   new.block
  761.   format.btitle "title" output.check
  762.   organization address new.block.checkb
  763.   organization output
  764.   address output
  765.   format.edition output
  766.   new.block
  767.   note output
  768.   fin.entry
  769. }
  770.  
  771. FUNCTION {mastersthesis}
  772. { output.bibitem
  773.   format.authors "author" output.check
  774.   author format.key output                              % special for
  775.   output.year.check                                     % apalike
  776.   new.block
  777. %  format.title "title" output.check
  778. %  new.block
  779.   "Master's thesis" emphasize format.thesis.type output.nonnull
  780.   school "school" output.check
  781.   address output
  782.   new.block
  783.   note output
  784.   fin.entry
  785. }
  786.  
  787. FUNCTION {misc}
  788. { output.bibitem
  789.   format.authors output
  790.   author format.key output                              % special for
  791.   output.year.check                                     % apalike
  792.   new.block
  793.   format.btitle output
  794.   new.block
  795.   howpublished output
  796.   new.block
  797.   note output
  798.   fin.entry
  799. }
  800.  
  801. FUNCTION {phdthesis}
  802. { output.bibitem
  803.   format.authors "author" output.check
  804.   author format.key output                              % special for
  805.   output.year.check                                     % apalike
  806.   new.block
  807. %  format.btitle "title" output.check
  808. %  new.block
  809.   "Ph.D. thesis" emphasize format.thesis.type output.nonnull
  810.   school "school" output.check
  811.   address output
  812.   new.block
  813.   note output
  814.   fin.entry
  815. }
  816.  
  817. FUNCTION {proceedings}
  818. { output.bibitem
  819.   format.editors output
  820.   editor format.key output                              % special for
  821.   output.year.check                                     % apalike
  822.   new.block
  823.   format.btitle "title" output.check
  824.   format.bvolume output
  825.   format.number.series output
  826.   address output                                % for apalike
  827.   new.sentence                                  % we always output
  828.   organization output                           % a nonempty organization
  829.   publisher output                              % here
  830.   new.block
  831.   note output
  832.   fin.entry
  833. }
  834.  
  835. FUNCTION {techreport}
  836. { output.bibitem
  837.   format.authors "author" output.check
  838.   author format.key output                              % special for
  839.   output.year.check                                     % apalike
  840.   new.block
  841.   format.btitle "title" output.check
  842.   new.block
  843.   format.tr.number output.nonnull
  844.   institution "institution" output.check
  845.   address output
  846.   new.block
  847.   note output
  848.   fin.entry
  849. }
  850.  
  851. FUNCTION {unpublished}
  852. { output.bibitem
  853.   format.authors "author" output.check
  854.   author format.key output                              % special for
  855.   output.year.check                                     % apalike
  856.   new.block
  857.   format.btitle "title" output.check
  858.   new.block
  859.   note "note" output.check
  860.   fin.entry
  861. }
  862.  
  863. FUNCTION {default.type} { misc }
  864.  
  865. MACRO {jan} {"Jan."}
  866.  
  867. MACRO {feb} {"Feb."}
  868.  
  869. MACRO {mar} {"Mar."}
  870.  
  871. MACRO {apr} {"Apr,"}
  872.  
  873. MACRO {may} {"May"}
  874.  
  875. MACRO {jun} {"June"}
  876.  
  877. MACRO {jul} {"July"}
  878.  
  879. MACRO {aug} {"Aug."}
  880.  
  881. MACRO {sep} {"Sept."}
  882.  
  883. MACRO {oct} {"Oct."}
  884.  
  885. MACRO {nov} {"Nov."}
  886.  
  887. MACRO {dec} {"Dec."}
  888.  
  889. READ
  890.  
  891. FUNCTION {sortify}
  892. { purify$
  893.   "l" change.case$
  894. }
  895.  
  896. INTEGERS { len }
  897.  
  898. FUNCTION {chop.word}
  899. { 's :=
  900.   'len :=
  901.   s #1 len substring$ =
  902.     { s len #1 + global.max$ substring$ }
  903.     's
  904.   if$
  905. }
  906.  
  907. %                       There are three apalike cases: one person (Jones),
  908. %                       two (Jones and de~Bruijn), and more (Jones et~al.).
  909. %                       This function is much like format.crossref.editors.
  910. %
  911. FUNCTION {format.lab.names}
  912. { 's :=
  913.   s #1 "{vv~}{ll}" format.name$
  914.   s num.names$ duplicate$
  915.   #2 >
  916.     { pop$ " et~al." * }
  917.     { #2 <
  918.         'skip$
  919.         { s #2 "{ff }{vv }{ll}{ jj}" format.name$ "others" =
  920.             { " et~al." * }
  921.             { " and " * s #2 "{vv~}{ll}" format.name$ * }
  922.           if$
  923.         }
  924.       if$
  925.     }
  926.   if$
  927. }
  928.  
  929. FUNCTION {author.key.label}
  930. { author empty$
  931.     { key empty$
  932.         { cite$ #1 #3 substring$ }
  933.         'key                                    % apalike uses the whole key
  934.       if$
  935.     }
  936.     { author format.lab.names }
  937.   if$
  938. }
  939.  
  940. FUNCTION {author.editor.key.label}
  941. { author empty$
  942.     { editor empty$
  943.         { key empty$
  944.             { cite$ #1 #3 substring$ }
  945.             'key                                % apalike uses the whole key
  946.           if$
  947.         }
  948.         { editor format.lab.names }
  949.       if$
  950.     }
  951.     { author format.lab.names }
  952.   if$
  953. }
  954.  
  955. FUNCTION {editor.key.label}
  956. { editor empty$
  957.     { key empty$
  958.         { cite$ #1 #3 substring$ }
  959.         'key                    % apalike uses the whole key, no organization
  960.       if$
  961.     }
  962.     { editor format.lab.names }
  963.   if$
  964. }
  965.  
  966. FUNCTION {calc.label}
  967. { type$ "book" =
  968.   type$ "inbook" =
  969.   or
  970.     'author.editor.key.label
  971.     { type$ "proceedings" =
  972.         'editor.key.label                       % apalike ignores organization
  973.         'author.key.label                       % for labeling and sorting
  974.       if$
  975.     }
  976.   if$
  977.   "\protect\astroncite{" swap$ * "}{"                   % these three lines are
  978.   *                                                     % for apalike, which
  979.   year field.or.null purify$ #-1 #4 substring$          % uses all four digits
  980.   *                       % the mathing closing "}" comes in at the reverse.pass
  981.   'label :=
  982. }
  983.  
  984. FUNCTION {sort.format.names}
  985. { 's :=
  986.   #1 'nameptr :=
  987.   ""
  988.   s num.names$ 'numnames :=
  989.   numnames 'namesleft :=
  990.     { namesleft #0 > }
  991.     { nameptr #1 >
  992.         { "   " * }
  993.         'skip$
  994.       if$                                               % apalike uses initials
  995.       s nameptr "{vv{ } }{ll{ }}{  f{ }}{  jj{ }}" format.name$ 't := % <= here
  996.       nameptr numnames = t "others" = and
  997.         { "et al" * }
  998.         { t sortify * }
  999.       if$
  1000.       nameptr #1 + 'nameptr :=
  1001.       namesleft #1 - 'namesleft :=
  1002.     }
  1003.   while$
  1004. }
  1005.  
  1006. FUNCTION {sort.format.title}
  1007. { 't :=
  1008.   "A " #2
  1009.     "An " #3
  1010.       "The " #4 t chop.word
  1011.     chop.word
  1012.   chop.word
  1013.   sortify
  1014.   #1 global.max$ substring$
  1015. }
  1016.  
  1017. FUNCTION {author.sort}
  1018. { author empty$
  1019.     { key empty$
  1020.         { "to sort, need author or key in " cite$ * warning$
  1021.           ""
  1022.         }
  1023.         { key sortify }
  1024.       if$
  1025.     }
  1026.     { author sort.format.names }
  1027.   if$
  1028. }
  1029.  
  1030. FUNCTION {author.editor.sort}
  1031. { author empty$
  1032.     { editor empty$
  1033.         { key empty$
  1034.             { "to sort, need author, editor, or key in " cite$ * warning$
  1035.               ""
  1036.             }
  1037.             { key sortify }
  1038.           if$
  1039.         }
  1040.         { editor sort.format.names }
  1041.       if$
  1042.     }
  1043.     { author sort.format.names }
  1044.   if$
  1045. }
  1046.  
  1047. FUNCTION {editor.sort}
  1048. { editor empty$
  1049.     { key empty$
  1050.         { "to sort, need editor or key in " cite$ * warning$
  1051.           ""
  1052.         }
  1053.         { key sortify }
  1054.       if$
  1055.     }
  1056.     { editor sort.format.names }
  1057.   if$
  1058. }
  1059.  
  1060. %                       apalike uses two sorting passes; the first one sets the
  1061. %                       labels so that the `a's, `b's, etc. can be computed;
  1062. %                       the second pass puts the references in "correct" order.
  1063. %                       The presort function is for the first pass. It computes
  1064. %                       label, sort.label, and title, and then concatenates.
  1065. FUNCTION {presort}
  1066. { calc.label
  1067.   label sortify
  1068.   "    "
  1069.   *
  1070.   type$ "book" =
  1071.   type$ "inbook" =
  1072.   or
  1073.     'author.editor.sort
  1074.     { type$ "proceedings" =
  1075.         'editor.sort
  1076.         'author.sort
  1077.       if$
  1078.     }
  1079.   if$
  1080.   #1 entry.max$ substring$      % for
  1081.   'sort.label :=                % apalike
  1082.   sort.label                    % style
  1083.   *
  1084.   "    "
  1085.   *
  1086.   title field.or.null
  1087.   sort.format.title
  1088.   *
  1089.   #1 entry.max$ substring$
  1090.   'sort.key$ :=
  1091. }
  1092.  
  1093. ITERATE {presort}
  1094.  
  1095. SORT            % by label, sort.label, title---for final label calculation
  1096.  
  1097. STRINGS { last.label next.extra }       % apalike labels are only for the text;
  1098.  
  1099. INTEGERS { last.extra.num }             % there are none in the bibliography
  1100.  
  1101. FUNCTION {initialize.extra.label.stuff} % and hence there is no `longest.label'
  1102. { #0 int.to.chr$ 'last.label :=
  1103.   "" 'next.extra :=
  1104.   #0 'last.extra.num :=
  1105. }
  1106.  
  1107. FUNCTION {forward.pass}
  1108. { last.label label =
  1109.     { last.extra.num #1 + 'last.extra.num :=
  1110.       last.extra.num int.to.chr$ 'extra.label :=
  1111.     }
  1112.     { "a" chr.to.int$ 'last.extra.num :=
  1113.       "" 'extra.label :=
  1114.       label 'last.label :=
  1115.     }
  1116.   if$
  1117. }
  1118.  
  1119. FUNCTION {reverse.pass}
  1120. { next.extra "b" =
  1121.     { "a" 'extra.label := }
  1122.     'skip$
  1123.   if$
  1124.   label extra.label * "}" * 'label :=
  1125.   extra.label 'next.extra :=
  1126. }
  1127.  
  1128. EXECUTE {initialize.extra.label.stuff}
  1129.  
  1130. ITERATE {forward.pass}
  1131.  
  1132. REVERSE {reverse.pass}
  1133.  
  1134. %                               Now that the label is right we sort for real,
  1135. %                               on sort.label then year then title.  This is
  1136. %                               for the second sorting pass.
  1137. FUNCTION {bib.sort.order}
  1138. { sort.label
  1139.   "    "
  1140.   *
  1141.   year field.or.null sortify
  1142.   *
  1143.   "    "
  1144.   *
  1145.   title field.or.null
  1146.   sort.format.title
  1147.   *
  1148.   #1 entry.max$ substring$
  1149.   'sort.key$ :=
  1150. }
  1151.  
  1152. ITERATE {bib.sort.order}
  1153.  
  1154. SORT            % by sort.label, year, title---giving final bibliography order
  1155.  
  1156. FUNCTION {begin.bib}
  1157. { preamble$ empty$                              % no \etalchar in apalike
  1158.     'skip$
  1159.     { preamble$ write$ newline$ }
  1160.   if$
  1161.   "\begin{thebibliography}{}" write$ newline$           % no labels in apalike
  1162. }
  1163.  
  1164. EXECUTE {begin.bib}
  1165.  
  1166. EXECUTE {init.state.consts}
  1167.  
  1168. ITERATE {call.type$}
  1169.  
  1170. FUNCTION {end.bib}
  1171. { newline$
  1172.   "\end{thebibliography}" write$ newline$
  1173. }
  1174.  
  1175. EXECUTE {end.bib}
  1176.